package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.dto.WarehouseAreaDTO;
import com.itheima.pojo.WarehouseArea;
import com.itheima.service.WarehouseAreaService;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/warehouseArea")
public class WarehouseAreaController {
    @Autowired
    private WarehouseAreaService warehouseAreaService;

    @GetMapping("/page")
    public Page<WarehouseAreaDTO> getWarehouseAreaPage(Page<WarehouseAreaDTO> page, WarehouseAreaDTO dto) {
        return warehouseAreaService.getWarehouseAreaPage(page, dto);
    }

    /**
     * 查询仓区列表
     *
     * @return
     */
    @GetMapping("/list")
    public Result getWarehouseAreaList() {
        return Result.success(warehouseAreaService.listAll());
    }


    @GetMapping("/{id}")
    public Result getWarehouseAreaById(@PathVariable Integer id) {
        return Result.success(warehouseAreaService.getWarehouseAreaById(id));
    }

    @PostMapping
    public Result saveWarehouseArea(@RequestBody WarehouseArea warehouseArea) {
        return Result.success(warehouseAreaService.saveWarehouseArea(warehouseArea));
    }

    @PutMapping
    public Result updateWarehouseArea(@RequestBody WarehouseArea warehouseArea) {
        return Result.success(warehouseAreaService.updateWarehouseArea(warehouseArea));
    }

    @DeleteMapping("/{id}")
    public Result deleteWarehouseArea(@PathVariable Integer id) {
        return Result.success(warehouseAreaService.deleteWarehouseArea(id));
    }
}
